using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Collections;
using Newtonsoft.Json;
using KingSite.Shop.Core.Service;
using KingSite.Shop.Service;
using KingSite.Shop.Domain;

namespace KingSite.Shop.Web.Controllers
{
    public class SkuController : Controller
    {
        ISkuService _service;

        public SkuController(ISkuService service) {
            _service = service;
        }
        //
        // GET: /Sku/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetAttribute() {
            int AttributeValue1 = string.IsNullOrEmpty(Request["AttributeValue1"]) ? 0 : Convert.ToInt32(Request["AttributeValue1"]);
            int AttributeValue2 = string.IsNullOrEmpty(Request["AttributeValue2"]) ? 0 : Convert.ToInt32(Request["AttributeValue2"]);
            int GoodsId = string.IsNullOrEmpty(Request["GoodsId"]) ? 0 : Convert.ToInt32(Request["GoodsId"]);
            JsonResult result = new JsonResult();
            Hashtable ht = new Hashtable();
            if ((AttributeValue1 > 0) && (AttributeValue2 > 0)) {
                int SkuId = _service.FindByValue1_2(GoodsId, AttributeValue1, AttributeValue2);
                ht.Add("SkuId", SkuId);
            }
            else if (AttributeValue1 > 0) {
                IList<Sku> list = _service.FindByValue1(GoodsId, AttributeValue1);
                ht.Add("SkuList", list);
            }
            else if (AttributeValue2 > 0) {
                IList<Sku> list = _service.FindByValue2(GoodsId, AttributeValue2);
                ht.Add("SkuList", list);
            }
            result.Data = ht;
            return result;
        }

    }
}
